/* 
    cnpm i mini-css-extract-plugin -D
    可以提取css

*/
const {resolve} = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

// 提取css文件插件
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    entry: './src/js/index.js',
    output: {
        filename: 'js/built.js',
        path: resolve(__dirname, 'build')
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    // 创建style标签将样式放入
                    // 'style-loader', 
                    // 取代style-loader，提取css成单独文件
                    MiniCssExtractPlugin.loader,
                    'css-loader'
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        }),
        new MiniCssExtractPlugin({
            // 对输出文件重命名
            filename: 'css/built.css',
        }),
    ],
    mode: 'development'
}